package com.hy.util;

import cn.hutool.captcha.generator.RandomGenerator;
import cn.hutool.core.util.StrUtil;

import java.util.Random;

public class StringUtil {
    private static final String BASE_STR = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
    private static final String USER_PRIFIX = "user_";
    private static final int USER_LEN = 20;

    /**
     *
     */
    public static String generateCode(int length) {
        RandomGenerator g = new RandomGenerator(BASE_STR, length);
        return g.generate();
    }

    public static String randomStr(int length) {
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            sb.append(BASE_STR.charAt(random.nextInt(length)));
        }

        return sb.toString();
    }

    public static String randomUserNameStr() {
        return USER_PRIFIX + randomStr(USER_LEN - USER_PRIFIX.length());
    }


    public static void main(String[] args) {
        randomStr(6);
    }
}
